# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Chloe Kudryavtsev <toast@toastin.space>
pkgname=minio
_pkgver='RELEASE.2020-05-16T01-33-21Z'
pkgver=${_pkgver#*.}
pkgver=${pkgver%T*}
pkgver=0.${pkgver//-}
pkgrel=0
pkgdesc="An open source object storage server compatible with Amazon S3"
pkgusers="minio"
pkggroups="minio"
url="https://minio.io/"
arch="all !mips !mips64" # fails to build on mips
license="Apache-2.0"
install="minio.pre-install"
makedepends="go"
source="
	minio.initd
	minio.confd
	$pkgname-$pkgver.tar.gz::https://github.com/minio/minio/archive/$_pkgver.tar.gz
	"
builddir="$srcdir/$pkgname-$_pkgver"
options="net"
subpackages="$pkgname-openrc"

export GOPATH="$srcdir"
export CGO_ENABLED=0

# secfixes:
#   0.20200423-r0:
#     - CVE-2020-11012

build() {
	local _ldflags=$(go run buildscripts/gen-ldflags.go 2> /dev/null)
	go build -tags kqueue --ldflags "$_ldflags" -o bin/minio
}

check() {
	# cmd: disk usage errors, like same as pkg/disk
	# pkg/disk: doesn't know what btrfs is
	# pkg/s3select: fails on 32bit systems
	# pkg/event/target: fails on aarch64
	# pkg/sys: fails on aarch64
	# cmd/http: fails on aarch64, suspect ipv6 problem
	# pkg/dsync: fails on armv7
	go test -tags kqueue $(go list ./... | grep -v \
		-e 'cmd$' \
		-e pkg/disk \
		-e pkg/s3select \
		-e pkg/event/target \
		-e pkg/sys \
		-e cmd/http \
		-e pkg/dsync
		)
}

package() {
	install -Dm755 "$builddir"/bin/minio \
		"$pkgdir"/usr/bin/minio
	install -Dm755 "$srcdir"/"$pkgname".initd \
		"$pkgdir"/etc/init.d/"$pkgname"
	install -Dm644 "$srcdir"/"$pkgname".confd \
		"$pkgdir"/etc/conf.d/"$pkgname"
}

cleanup_srcdir() {
	go clean -modcache
	default_cleanup_srcdir
}

sha512sums="6427a225d4e6c51cc5de077ccd29ddf52556722cf958e83e480df1c5882aa4fa7daebfeb970e80f8f9c3176594d8e427e8c8dbf268ce945647a11bdf1e69affd  minio.initd
ed9790fbadfb38e4d660eb1befd87e803d70dec04d936e8cd26def4a9c21240bb7cae8750ae3395aa4761e6738b9e346c86ba57761cfde30efe46d2cb459a7e4  minio.confd
2526ffeacb220bb91a6882863bffaff40f8b3e2e7d71d33b99879e46ace48d2636484aaa48c830c7880f529552338005a29e2806226eee743f0a47310bfc2a7c  minio-0.20200516.tar.gz"
